remove_decimal_zeros Subroutine

public subroutine remove_decimal_zeros(str, result)

Removes trailing zeros after the decimal point in a string.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Input: String to remove zeros from.

character(len=*), intent(out) :: result

Output: String without trailing zeros.


Called by

proc~~remove_decimal_zeros~~CalledByGraph proc~remove_decimal_zeros remove_decimal_zeros program~game24_ultra game24_ultra program~game24_ultra->proc~remove_decimal_zeros

Source Code

    subroutine remove_decimal_zeros(str, result)
        !! Removes trailing zeros after the decimal point in a string.
        character(len=*), intent(in)  :: str
        !! Input: String to remove zeros from.
        character(len=*), intent(out) :: result
        !! Output: String without trailing zeros.
        integer                        :: i, len_str
        !! Loop counter and string length.

        len_str = len_trim(str)
        result = adjustl(str(1:len_str))

        ! Find the position of the decimal point
        i = index(result, '.')

        ! If there's a decimal point, remove trailing zeros
        if (i > 0) then
            do while (len_str > i .and. result(len_str:len_str) == '0')
                len_str = len_str - 1
            end do
            if (result(len_str:len_str) == '.') len_str = len_str - 1
            result = result(1:len_str)
        end if
    end subroutine remove_decimal_zeros